<?php
class BreadcrumbWidget extends Widget
{
    protected $path;
    
    public function init($params){
        parent::init($params);    
    }
    
    public function setPath($params){
        if (!empty($params))
        {   
            $this->path = array('Home' => base_url());
        
            /*
            *  merge array : $this->path = array_merge($this->path, $params); 
            * We can not user array_merge for case project title is number only : see help on array_merge function below
            * If only one array is given and the array is numerically indexed, the keys get reindexed in a continuous way.
            */
            foreach ($params as $key=>$value)
            {
                $this->path[$key] = $value;   
            }
        }
    }
    
    public function run()
    {     
        foreach($this->path as $title => $urlInfo){
            
            if (!is_array($urlInfo))
            {
                if(substr($urlInfo,0,4) != 'http')
                {
                    $this->path[$title] =  base_url($urlInfo);
                }
                else
                {
                    $this->path[$title] = $urlInfo;
                }
            }
            
        }
        $this->render(array('pathItems' => $this->path));
    }
}
?>
